package Semester_4.AOP.JDKDynamicProxy.intensifier;
import Semester_4.AOP.JDKDynamicProxy.DAO.UserDAO;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class SpringAOP implements InvocationHandler {
    UserDAO ud ;
    public Object createProxy(UserDAO ud){
        this.ud = ud;
        ClassLoader loader = SpringAOP.class.getClassLoader();
        Class<?>[] classes = ud.getClass().getInterfaces();
        return Proxy.newProxyInstance(loader,classes,this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        MyAspect ms = new MyAspect();
        ms.chinkPermissions();
        Object invoke = method.invoke(ud, args);
        ms.log();
        return invoke;
    }
}
